// ActionScript file
import mx.messaging.channels.StreamingAMFChannel;
import mx.events.DragEvent;
import mx.events.CloseEvent;
import mx.controls.Alert;

private function createNewWindow(w:ResizableWindow):void {
   w.x = 100 + this.numChildren * 20;
   w.y = 50 + this.numChildren * 20;
   this.addChild(w); 
}

private function onComplete():void {
   this.myFolderBox.addEventListener(MouseEvent.MOUSE_DOWN, iconDragHandler);
   this.myFolderBox.addEventListener(MouseEvent.MOUSE_UP, iconOverHandler);
   this.myAppBox.addEventListener(MouseEvent.MOUSE_DOWN, iconDragHandler);
   this.myAppBox.addEventListener(MouseEvent.MOUSE_UP, iconOverHandler);
   this.myComputerBox.addEventListener(MouseEvent.MOUSE_DOWN, iconDragHandler);
   this.myComputerBox.addEventListener(MouseEvent.MOUSE_UP, iconOverHandler);
   this.myTrashBox.addEventListener(MouseEvent.MOUSE_DOWN, iconDragHandler);
   this.myTrashBox.addEventListener(MouseEvent.MOUSE_UP, iconOverHandler);
}  

private function iconOverHandler(event:MouseEvent):void {
   if(event.target is VBox) 
      event.target.removeEventListener(MouseEvent.MOUSE_MOVE, iconMoveHandler);
   else 
      event.target.parent.removeEventListener(MouseEvent.MOUSE_MOVE, iconMoveHandler);
}

private function iconDragHandler(event:MouseEvent):void {
   if(event.target is VBox) 
      event.target.addEventListener(MouseEvent.MOUSE_MOVE, iconMoveHandler);
   else 
      event.target.parent.addEventListener(MouseEvent.MOUSE_MOVE, iconMoveHandler);          
}  

private function iconMoveHandler(event:MouseEvent):void {
   Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, iconDragDropHandler);
   if(event.target is VBox) 
      event.target.addEventListener(DragEvent.DRAG_DROP,iconDragDropHandler);
   else
      event.target.parent.addEventListener(DragEvent.DRAG_DROP,iconDragDropHandler);
   if(event.target is VBox) 
      event.target.startDrag(false);
   else 
      event.target.parent.startDrag(false);
}  
         

public function iconDragDropHandler(event:MouseEvent):void {
   this.stopDrag();
}

[Embed(source="assets/demo/ic_warning.png")] 
[Bindable] public var iconSymbol:Class; 

private function showAlert(title:String, msg:String) :void{
   var a:Alert;   
   a = Alert.show(msg,title,Alert.OK | Alert.CANCEL, this,null, iconSymbol,  Alert.OK );
   a.height = 130;
   a.width = 360;  
}